package com.example.simple.mall.contorller;

import com.example.simple.mall.bean.User;
import com.example.simple.mall.common.ServerResponse;
import com.example.simple.mall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by IntelliJ IDEA.
 *
 * @author ouyangzhixiang
 * @date 2018/6/19
 */
@RestController
@RequestMapping("/user/")
public class UserContorller {

    private final IUserService iUserService;

    @Autowired
    public UserContorller(IUserService iUserService) {
        this.iUserService = iUserService;
    }

    /**
     * 用戶登陸
     *
     * @param username
     * @param password
     * @return
     */
    @RequestMapping(value = "login", method = RequestMethod.POST)
    public ServerResponse<User> login(String username, String password) {
        ServerResponse<User> response = iUserService.selectelogin(username, password);
        return response;
    }

    @RequestMapping(value = "reboot", method = RequestMethod.POST)
    public ServerResponse<User> reboot(String username, String password) {
        ServerResponse<User> response = iUserService.reboot(username, password);
        return response;
    }

    @RequestMapping(value = "password_reset", method = RequestMethod.POST)
    public ServerResponse<User> passwordReset(String email) {
        return iUserService.passwordReset(email);
    }

    /**
     * 用戶注冊
     *
     * @param user
     * @return
     */
    @RequestMapping(value = "registered", method = RequestMethod.POST)
    public ServerResponse<User> registered(User user) {
        ServerResponse<User> response = iUserService.registered(user);
        return response;
    }
}
